import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { RolePermission } from './role-permission.entity';

@Entity('permissions')
export class Permission {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'varchar', length: 100, unique: true, comment: '权限代码' })
  code: string;

  @Column({ type: 'varchar', length: 100, comment: '权限名称' })
  name: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '权限描述' })
  description?: string;

  @Column({ type: 'varchar', length: 50, comment: '权限类型：menu-菜单，button-按钮，api-接口' })
  type: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '资源路径' })
  resource?: string;

  @Column({ type: 'tinyint', default: 1, comment: '状态：1-启用，0-禁用' })
  status: number;

  @Column({ type: 'int', default: 0, comment: '排序' })
  sort: number;

  @CreateDateColumn({ comment: '创建时间' })
  createTime: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updateTime: Date;

  @OneToMany(() => RolePermission, rolePermission => rolePermission.permission)
  rolePermissions: RolePermission[];
}